<?php
/** $Id: default_form.php 11917 2009-05-29 19:37:05Z ian $ */
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
			<?php 
			$app = JFactory::getApplication();
			$template = JURI::base() . 'templates/' . $app->getTemplate();
	
			$session =& JFactory::getSession();  
			
			$user = JFactory::getUser();
			//$groups = JUserHelper::getUserGroups($user->id);
			//print_r($groups);
			
					if ($user->get('guest') == 1) {
						// Redirect to profile page.
						header('Location: '.substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], 'index.php')).'index.php');
						//return;
					}
			
		  if(isset($_POST['frm_1']))  {	
		  
				$session->set( 'landsdel', $_POST['region']);
				$session->set( 'pris', $_POST['catid']);
				$session->set( 'search_text', $_POST['search_text']);				
				$session->set( 'sort', $_POST['sort']);
				
				$landsdel_start=substr($session->get( 'landsdel'),0,4);
				$landsdel_end=substr($session->get( 'landsdel'),5,4);
				$pris=$session->get('pris');
				$search_text=$session->get('search_text');
				$sort=$session->get('sort');
				
				//$query = "SELECT * FROM #__jobs ";
				
				$query = "SELECT if(count(a.id)>=3,1,0) as 'close',a.* FROM #__jobs a LEFT JOIN  #__uworks b ON a.id = b.jobid ";
				
				
				if($session->get('landsdel')=='0-0') {
					$query .= " WHERE postcode >=0 and postcode <=10000";
				}
				else {
					$query .= " WHERE postcode >=$landsdel_start and postcode <=$landsdel_end";
				}
				
				if($pris!=0) $query.= " AND a.catid=$pris" ;
				if($search_text!="") $query .= " AND (a.title like '%".$search_text."%' or a.description like '%".$search_text."%' or postcode like '%".$search_text."%' ) ";				
				
				$query .= " AND a.state = 1 ";
				$query .= " GROUP BY a.id ";
				//SELECT count(a.id) as 'close',a.* FROM i0y7t_jobs a LEFT JOIN  i0y7t_uworks b ON a.id = b.jobid WHERE postcode >=0 and postcode <=10000   AND a.state = 1  GROUP BY a.id order by close,a.close_project_bid,a.catid
				
				
				switch ($sort){
					case '1':{ $query.= " order by created desc";	break;	}
					case '2': {	$query.= " order by close,close_project_bid,deadline";	break;	}
					case '3': {	$query.= " order by close,close_project_bid,catid desc";	break; }
				    case '4': { $query.= " order by close,close_project_bid,postcode"; break; }		
					default : $query.= " order by close,close_project_bid,id desc"; break;	   
				};	
				
				//echo $query;
		  } else {
			
			//$query = "SELECT * FROM #__jobs WHERE state = 1 order by id desc";
				//$query = "SELECT * FROM #__jobs WHERE state = 1 ";
				
				$query = "SELECT if(count(a.id)>=3,1,0) as 'close',a.* FROM #__jobs a LEFT JOIN  #__uworks b ON a.id = b.jobid WHERE a.state = 1 ";
				
				if($session->get('landsdel') ) {
					$landsdel_start=substr($session->get( 'landsdel'),0,4);
					$landsdel_end=substr($session->get( 'landsdel'),5,4);
					
					if($session->get('landsdel')=='0-0') {
						$query .= "AND postcode >=0 and postcode <=10000";
					}
					else {
						$query .= "AND postcode >=$landsdel_start and postcode <=$landsdel_end";
					}				
				}
				if($session->get( 'pris') ) {
					$pris=$session->get('pris');
					if($pris!=0) $query.= " AND a.catid=$pris" ;
				}
				
				if($session->get( 'search_text') ) {
					$search_text=$session->get('search_text');
					if($search_text!="") $query .= " AND (a.title like '%".$search_text."%' or a.description like '%".$search_text."%' or postcode like '%".$search_text."%' ) ";
				}
				
				//$query .= " AND a.state = 1 ";
				$query .= " GROUP BY a.id ";
				
				if($session->get( 'sort') ) {
					$sort=$session->get('sort');
					switch ($sort){
					case '1':{ $query.= " order by created desc";	break;	}
					case '2': {	$query.= " order by close,close_project_bid,deadline";	break;	}
					case '3': {	$query.= " order by close,close_project_bid,catid desc ";	break; }
				    case '4': { $query.= " order by close,close_project_bid,postcode"; break; }		
					default : $query.= " order by close,close_project_bid,id desc"; break;	   
					};	
				} else {
					$query.= " order by close,close_project_bid,id desc";	   
				}
				//$query .= " AND id NOT IN (SELECT jobid FROM #__uworks WHERE state !=-2) ";
				
				//echo $query;
			
		  }
		  $db =& JFactory::getDBO(); 
		  $limitstart	= JRequest::getVar('limitstart', 0, '', 'int');		  
		  $db->setQuery( $query );
		  $row = $db->loadObjectList();
		  $count=count($row);
		  //echo $count;
		  $paging_limit_1 = 15;
		  $query.=" limit $limitstart,". $paging_limit_1;
		  
		//echo $query;
		  
		  if(isset($_GET['tab']) && $_GET['tab']==2) {			 
			  ?>
             <script type="text/javascript">
			 	$(document).ready(function($) {	
	            $('#sogOpgaver .tabs li:last a').click()
				});
            </script>
            <?php
		  }
		 
		
		 
		  
		  // process frm 2
		  if(isset($_POST['frm_2']))  {	
		  	  ?>
             <script type="text/javascript">
			 	$(document).ready(function($) {	
	           		 $('#sogOpgaver .tabs li:last a').click();
				});
            </script>
            <?php
				$session->set( 'landsdel_2', $_POST['region_2']);
				$session->set( 'pris_2', $_POST['catid_2']);
				$session->set( 'search_text_2', $_POST['search_text_2']);				
				$session->set( 'sort_2', $_POST['sort_2']);
				
				$landsdel_start=substr($session->get( 'landsdel_2'),0,4);
				$landsdel_end=substr($session->get( 'landsdel_2'),5,4);
				$pris=$session->get('pris_2');
				$search_text=$session->get('search_text_2');
				$sort=$session->get('sort_2');
				
				//$query_2 = "SELECT * FROM #__jobs ";
				$query_2 = "SELECT a.*,b.catid,a.catid as 'priscat' FROM #__jobs a INNER JOIN #__uworks b ON a.id=b.jobid  WHERE (b.state!=-2 AND b.userid=".$user->id.") AND  a.state = 1 ";
				
				if($session->get('landsdel_2')=='0-0') {
					$query_2 .= " AND postcode >=0 and postcode <=10000";
				}
				else {
					$query_2 .= " AND postcode >=$landsdel_start and postcode <=$landsdel_end";
				}
				//$query_2 .= " WHERE postcode >=$landsdel_start and postcode <=$landsdel_end";
				if($pris!=0) $query_2.= " AND a.catid=$pris" ;
				if($search_text!="") $query_2 .= " AND (a.title like '%".$search_text."%' or a.description like '%".$search_text."%' or postcode like '%".$search_text."%' ) ";				
				//$query_2 .= " AND id  IN (SELECT jobid FROM #__uworks WHERE state !=-2 AND userid=".$user->id." ) ";
				//$query_2 .= " AND state = 1 ";
				switch ($sort){
					case '1':{ $query_2.= " order by created desc";	break;	}
					case '2': {	$query_2.= " order by a.close_project , deadline";	break;	}
					case '3': {	$query_2.= " order by a.close_project , a.catid  ";	break; }
				    case '4': { $query_2.= " order by a.close_project , postcode"; break; }
					case '5': { $query_2.= " order by a.close_project , b.catid"; break; }
					default : $query_2.= " order by a.close_project , id desc"; break;				   
				};	
				
				//echo $query_2;
		  } else {
			//$query_2 = "SELECT * FROM #__jobs WHERE id IN (SELECT jobid FROM #__uworks WHERE state !=-2 AND userid=".$user->id." ) AND state = 1   ";
				$query_2 = "SELECT a.*,b.catid ,a.catid as 'priscat' FROM #__jobs a INNER JOIN #__uworks b ON a.id=b.jobid  WHERE (b.state!=-2 AND b.userid=".$user->id.") AND  a.state = 1 ";
				if($session->get('pris_2')) {
					$pris=$session->get('pris_2');
					if($pris!=0) $query_2.= " AND a.catid=$pris" ;
				}
				if($session->get('search_text_2')) {
					$search_text=$session->get('search_text_2');
					if($search_text!="") $query_2 .= " AND (a.title like '%".$search_text."%' or a.description like '%".$search_text."%' or postcode like '%".$search_text."%' ) ";	
				}
				
				
				if($session->get('landsdel_2')) {
					$landsdel_start=substr($session->get( 'landsdel_2'),0,4);
					$landsdel_end=substr($session->get( 'landsdel_2'),5,4);
					if($session->get('landsdel_2')=='0-0') {
						$query_2 .= " AND postcode >=0 and postcode <=10000";
					}
					else {
						$query_2 .= " AND postcode >=$landsdel_start and postcode <=$landsdel_end";
					}
				}
				
				//$query_2 .= " WHERE postcode >=$landsdel_start and postcode <=$landsdel_end";
				
				
							
				//$query_2 .= " AND id  IN (SELECT jobid FROM #__uworks WHERE state !=-2 AND userid=".$user->id." ) ";
				//$query_2 .= " AND state = 1 ";
				
				if($session->get('sort_2')) {
					$sort=$session->get('sort_2');
					switch ($sort){
					case '1':{ $query_2.= " order by created desc";	break;	}
					case '2': {	$query_2.= " order by a.close_project , deadline";	break;	}
					case '3': {	$query_2.= " order by a.close_project , a.catid";	break; }
				    case '4': { $query_2.= " order by a.close_project , postcode"; break; }	
					case '5': { $query_2.= " order by a.close_project , b.catid"; break; }	
					default : $query_2.= " order by a.close_project , id desc"; break;			   
					};	
				} else {
					$query_2.= " order by a.close_project , id desc";	
				}
				//echo $query_2;
			
		  }
		 
		  $limitstart_2	= JRequest::getVar('limitstart2', 0, '', 'int');		 
		  
		  $db->setQuery( $query_2 );
		  $row2 = $db->loadObjectList();
		  $count_2=count($row2);
		  $paging_limit_2 = 15;
		  $query_2.=" limit $limitstart_2,".$paging_limit_2;
		  //echo $query_2;
		  
		  ?>
           <script type="text/javascript">
            $(document).ready(function($) {	            		
				$('#pagin1 a').each(function(index) {
					$(this).attr("href",$(this).attr("href")+"&tab=1");
					
				});    		
				$('#pagin2 a').each(function(index) {
					
					$(this).attr("href",$(this).attr("href")+"&tab=2");
					
				});  
				
				$('#pagin1 .disabled').attr("href",'javascript:onclick(void(0))');	
				$('#pagin2 .disabled').attr("href",'javascript:onclick(void(0))');			
						
            });
			
            </script>
            
			<div class="inner clearfix">
                        <!--Sog-->
                        <div id="sogOpgaver" class="w698 fll">
                        	<ul class="tabs">
                                <li class="first"><a href="#sogMaleropgaver" >Søg maleropgaver</a></li>
                                <li class="last"><a href="#myOpgaver" >Mine opgaver</a></li>
                            </ul>
                            
                        	<div id="sogMaleropgaver" class="tab-content-ctn w751 bor-std">
                            	<div class="tab-content-inner">
                                <form class="search-opgaver-form" method="post" action="index.php?option=com_jobs&view=myjobs&start=0&tab=1" id="search_form">
                                	<div class="search-form legend">
                                    	<h3 class="title">Afgræns din søgning</h3>
                                    	
                                        	<fieldset>
                                            	<p class="input-set odd">
                                                	<label>Landsdel:</label>
                                                    <?php echo $this->city_html;?>
                                                </p>
                                                <p class="input-set">
                                                	<label>Estimeret pris:</label>
                                                    <?php echo $this->pris_html;?>
                                                </p>
                                                <p class="input-set odd">
                                                	<label>Søg efter specifik tekst:</label>
                                                    <input name="search_text" id="search_text" class="input-txt" title="Her kan du skrive evt. specifikke søgeord..." value="<?php if(isset($_POST['frm_1']) ) echo $session->get('search_text');  ?>" />
                                                </p>
                                                 <input type="hidden" name="frm_1" value="frm_1" />
                                                 
                                                <input class="button search-btn flr" alt="" type="submit" value="Søg" name="search" />
                                            </fieldset>
                                       
                                    	
                                    </div>
                                    
                                    <div class="search-results">
                                    	<div class="sort">
                                        	Søgeresultater: <?php echo $count;?>
                                        	<p class="input-set flr">
                                            	<label>Sortér efter:</label>
                                                <select id="sort" name="sort" onchange="$('#search_form').submit();">
                                                <?php for($i=0;$i<sizeof($this->jsort);$i++) { ?>
                                               
                                               		<option <?php if($session->get('sort')==$this->jsort[$i]['value']) echo "selected"?> value="<?php echo $this->jsort[$i]['value'];?>"><?php echo $this->jsort[$i]['name'];?></option>
                                                <?php } ?>
                                                                                                    
                                                </select>
                                            </p>
                                        </div>
                                    	<ul class="tasks-list">
                                        	<?php 
                                        	 
											 
											 
											  $db->setQuery( $query );
											  $row = $db->loadObjectList();
											 											 
											  
											  for($i=0;$i<count($row);$i++)
											  {	             
											  
											      $query = "SELECT count(*) as total FROM #__uworks WHERE state != -2 AND userid = ".$user->id." AND jobid = ".$row[$i]->id;
												 
												  $db->setQuery( $query );
												  $rowcountuser = $db->loadObject();
													
												  $query = "SELECT count(*) as total FROM #__uworks WHERE state != -2 AND jobid=".$row[$i]->id;
												  $db->setQuery( $query );
												  $rowcount = $db->loadObject();
											?>
                                        	<li class="<?php if($i%2==0) echo "odd"; else echo "even"?>">
                                            	<div class="info fll">
                                                	<p>
                                                    	<?php
														if(($rowcountuser->total==0 && $rowcount->total <=2 && 	$row[$i]->close_project_bid==0) )
														{
															if( isset($user->groups[8])) {
																?>
                                                                <a onclick="getInfoJob(<?php echo $row[$i]->id ;?>);" class="task-title">
                                                                <span class="task-id">ID<?php echo $row[$i]->id;?></span> - <span class="task-name"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->title),35,'...') ;?></span>
                                                                </a>
                                                                <?php
															} else {
															
                                                        ?>
                                                    	<a onclick="getInfo(<?php echo $row[$i]->id ;?>);" class="thickbox task-title ">
                                                        	<span class="task-id">ID<?php echo $row[$i]->id;?></span> - <span class="task-name"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->title),35,'...') ;?></span>
                                                        </a>
                                                        <?php
															}
														} else {
															if( isset($user->groups[8])) {
																?>
                                                                <a onclick="getInfoJob(<?php echo $row[$i]->id ;?>);" class="task-title disabled">
                                                                <span class="task-id">ID<?php echo $row[$i]->id;?></span> - <span class="task-name"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->title),35,'...') ;?></span>
                                                                </a>
                                                                <?php
															} else {
															?>
                                                            <a class="task-title disabled">
                                                            <span class="task-id">ID<?php echo $row[$i]->id;?></span> - <span class="task-name"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->title),35,'...') ;?></span>
                                                            </a>
                                                            <?php
															}
														}
                                                        ?>
                                                        <span class="date">(Oprettet d. <?php echo JHtml::_('date', $row[$i]->created , JText::_('DATE_FORMAT_LC6')) ;?>)</span>
                                                    </p>
                                                    <p class="short-desc"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->description),80,'...') ;?></p>
                                                    <p class="date-price"> <span class="region">Landsdel: <?php echo $this->items_job->getNameCityDanish($row[$i]->postcode);?></span> • Postnr. <?php echo $row[$i]->postcode;?> • <span class="price">Estimeret pris: <?php echo $this->items_job->getPrisJob($row[$i]->catid)->title;?></span></p>
                                                </div>
                                                <?php
														if($rowcountuser->total==0 && $rowcount->total <=2 && 	$row[$i]->close_project_bid==0)
														{
                                                        ?>
                                                <a class="button thickbox flr" onclick="getInfo(<?php echo $row[$i]->id ;?>);">Gå til opgave</a> 
												<?php
														} else {
															if($row[$i]->close_project_bid==1 || $rowcount->total >2) {
																
															?>
                                                 <a class="button flr btndisable" >Lukket</a> 
                                                            <?php
															} else {
																?>
                                                                <a class="button thickbox flr" onclick="getInfo(<?php echo $row[$i]->id ;?>);" style="color:#008E00;" >Allerede købt</a> 
                                                                <?php
															}
														}
                                                        ?>
												<a style="display:none;" id="btnpupfr" class="button thickbox flr" href="#TB_inline?height=390&width=500&inlineId=hiddenDetailContent">Gå til opgave</a>
                                                
                                            </li>
                                        	<?php }?>                                        	
                                        </ul>
                                        <div class="pagination"  id="pagin1">
                                            <?php 
                                              jimport('joomla.html.pagination');
                                              
                                              //echo $limitstart;
                                              $pagination = new JPagination($count, $limitstart, $paging_limit_1);
                                              echo $pagination->getPagesLinks();
                                            ?>                                           
                                        </div>
                                    </div>
                                    </form>
                                </div>
                            </div>
                             <a style="display:none;" id="btnmyjobdetail" class="button thickbox flr" href="#TB_inline?height=450&width=650&inlineId=hiddenViewContent">Gå til opgave</a>
                          
                            <!--My Opgaver-->
                            <div id="myOpgaver" class="tab-content-ctn w751 bor-std">
                            
                            	<div class="tab-content-inner">
                                <form class="search-opgaver-form" method="post" action="index.php?option=com_jobs&view=myjobs&start=0&tab=2" id="search_form2">                               
                                	<div class="search-form legend">
                                    	<h3 class="title">Afgræns din søgning</h3>
                                    	
                                        	<fieldset>
                                            	<p class="input-set odd">
                                                	<label>Landsdel:</label>
                                                    <?php echo $this->city_html_2;?>
                                                </p>
                                                <p class="input-set">
                                                	<label>Estimeret pris:</label>
                                                    <?php echo $this->pris_html_2;?>
                                                </p>
                                                <p class="input-set odd">
                                                	<label>Søg efter specifik tekst:</label>
                                                   <input name="search_text_2" id="search_text_2" class="input-txt" title="Her kan du skrive evt. specifikke søgeord..." value="<?php if(isset($_POST['frm_2'])) echo $session->get('search_text_2');  ?>" />
                                                </p>
                                                <input type="hidden" name="frm_2" value="frm_2" />
                                                <input class="button search-btn flr" alt="" type="submit" value="Søg" />
                                            </fieldset>
                                       
                                    	
                                    </div>
                                    
                                    <div class="search-results">
                                    	<div class="sort">
                                        	Søgeresultater: <?php echo $count_2;?>
                                        	<p class="input-set flr">
                                            	<label>Sortér efter:</label>
                                                <select id="sort_2" name="sort_2" onchange="$('#search_form2').submit();">
                                                <?php for($i=0;$i<sizeof($this->jsort_2);$i++) { ?>
                                               
                                               		<option <?php if($session->get('sort_2')==$this->jsort_2[$i]['value']) echo "selected"?> value="<?php echo $this->jsort_2[$i]['value'];?>"><?php echo $this->jsort_2[$i]['name'];?></option>
                                                <?php } ?>
                                                                                                    
                                                </select>
                                            </p>
                                        </div>
                                        </form>
                                    	<ul class="tasks-list mine-opagver">
                                        
                                        <?php 
                                        	 
											  $db->setQuery( $query_2 );
											  $row = $db->loadObjectList();
											  for($i=0;$i<count($row);$i++)
											  {	  
											  $uwork = $this->items_job->getUserWorkInfo($user->id,$row[$i]->id);
											?>
                                        	<li class="<?php if($i%2==0) echo "odd"; else echo "even"?>">
                                            	<div class="info fll" id="wok<?php echo $uwork->id;?>">
                                                	<p>
                                                    <?php
													
													if($uwork->catid==44||$uwork->catid==45)
													{
														
															if($row[$i]->close_project==1) 
															{
																?>
                                                                <a onclick="getInfoJob(<?php echo $row[$i]->id;?>)" class="task-title disabled">
                                                        <span class="task-id " >ID<?php echo $row[$i]->id;?> - <span class="task-name"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->title),35,'...') ;?></span>
                                                        </a>
                                                                <?php
															} 
															else 
															{	
																?>
                                                                <a onclick="getInfoJob(<?php echo $row[$i]->id;?>)" class="task-title <?php if($uwork->catid==44) echo 'green'; else  echo 'disabled';?> ">
                                                        <span class="task-id " >ID<?php echo $row[$i]->id;?> - <span class="task-name"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->title),35,'...') ;?></span>
                                                        </a>
                                                                <?php
															}
														?>
                                                        
                                                        <span class="date">(Oprettet d. <?php echo JHtml::_('date', $row[$i]->created , JText::_('DATE_FORMAT_LC6')) ;?>)</span>
                                                        <?php
														
												    } else {
														?>
                                                        <a onclick="getInfoJob(<?php echo $row[$i]->id;?>)"  class="task-title <?php if($row[$i]->close_project==1) echo 'disabled';?>">
                                                        	<span class="task-id">ID<?php echo $row[$i]->id;?></span> - <span class="task-name"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->title),35,'...') ;?></span>
                                                        </a>
                                                        <span class="date">(Oprettet d. <?php echo JHtml::_('date', $row[$i]->created , JText::_('DATE_FORMAT_LC6')) ;?>)</span>
                                                        <?php
													}
                                                    ?>
                                                    
                                                    </p>
                                                    <p class="short-desc"><?php echo $this->items_job->trunchtml( strip_tags($row[$i]->description),80,'...') ;?></p>
                                                    <p class="date-price"><span class="region">Landsdel: <?php echo $this->items_job->getNameCityDanish($row[$i]->postcode);?></span> • Postnr. <?php echo $row[$i]->postcode;?> • <span class="price">Estimeret pris: <?php echo $this->items_job->getPrisJob($row[$i]->priscat)->title;?></span></p>
                                                </div>
                                               
                                               <div class="status flr">
                                               <form method="post" action="index.php?option=com_jobs&view=myjobs" id="myjob-status">
                                                    <?php	
													/*
															if( $row[$i]->close_project==1) 
															{
																echo $this->items_job->getListWorks(45,'works_'.$uwork->id);											
															}else 
															{
																echo $this->items_job->getListWorks($uwork->catid,'works_'.$uwork->id);											
															}
													 */		 
													 echo $this->items_job->getListWorks($uwork->catid,'works_'.$uwork->id,$row[$i]->close_project);																							
													 ?>
                                                        <div class="button-holder">
                                                        	<!--<a class="button marl10 thickbox" onclick="getInfoJob(<?php echo $row[$i]->id;?>);">Se mere</a>-->
                                                            <?php
															if( $row[$i]->close_project==1) 
															{
															?>
                                                            <a class="button btndisable" onclick="getInfoJob(<?php echo $row[$i]->id;?>)" id="btn_sb_<?php echo $uwork->id;?>" >Opgave lukket</a>
                                                            <?php
															} else {
																?>
                                                            <a class="button" id="btn_sb_<?php echo $uwork->id;?>" onclick="processMyJobStatus(<?php echo $uwork->id;?>,<?php echo $uwork->catid; ?>,<?php echo $row[$i]->id; ?>);" >Opdatér status</a>     
                                                                <?php
															}
                                                            ?>                         
                                                        	<a class="button thickbox" href="#TB_inline?height=100&width=400&inlineId=hiddenViewMyJobStatus" id="btnjobstatus"  style="display:none;">Opdatér status</a>                                                </div>                                                                                                           
                                                    <a style="display:none;" id="btnmyjobdetail" class="button thickbox flr" href="#TB_inline?height=450&width=650&inlineId=hiddenViewContent">Gå til opgave</a>
                                                    </form>
                                                </div>
                                                
                                            </li>
                                        	<?php }?>    
                                        
                                        </ul>
                                         <div class="pagination" id="pagin2">
                                            <?php 
                                              jimport('joomla.html.pagination1');
                                              
                                              //echo $limitstart;
                                              $pagination = new JPagination1($count_2, $limitstart_2, $paging_limit_2);
                                              echo $pagination->getPagesLinks1();
                                            ?>                                           
                                        </div>
                                    </div>
                                     
                                </div>
                            
                            </div>
                        </div>
                        <!-- /Sog-->
                        
                        
                        <!-- Sidebar-->
                          <?php $infositebar = getArticles(48);
							  $imagesb = json_decode($infositebar[0]->images);
						?>
                       
                       
                        
                        <div id="sidebar" class="w210 bor-std flr" style=" <?php if (is_file($imagesb->image_intro)) {echo "background: url('".$imagesb->image_intro."') no-repeat scroll left bottom #FFFFFF;";} else {echo "background: url('templates/3dmaler/img/side-img.jpg') no-repeat scroll left bottom #FFFFFF;";} ;?>  ">
                        	<div class="sidebar-inner pad10">
                            
                                <div id="newsletter" class="legend">
                                	<div class="inner">
										
                                        <p><a class="newletter-btn flr" href="javascript:void(0)" onclick="javascript:toggleDiv('newsletterForm');"><img src="<?php echo $template; ?>/img/newsletter-icon.jpg"></a> Tilmeld Nyhedsbrev</p>
                                        <div id="newsletterForm" style="display:none;">
                                            <form id="nyhedsbrevForm" method="" action="">
                                                <fieldset>
                                                    <p class="input-set">
                                                        <input class="input-txt" type="text" id="newsletteremail" title="Indsæt din e-mail" value="" />
                                                    </p>
                                                    <div class="form-submit">
                                                    	<input onclick="$('#hiddenDetailContent').html('');checkEmailDisable($('#newsletteremail').val())" class="button send-btn flr" type="button" value="Afmeld" />
                                                         <input onclick="$('#hiddenDetailContent').html('');checkEmailValid($('#newsletteremail').val())"  class="button send-btn flr" type="button" value="Tilmeld" />
                                                         
                                                        <input id="btn_nyh_thank" type="hidden" class="button send-btn thickbox flr" alt="#TB_inline?height=100&width=340&inlineId=tilmeldConfirm" value="Tilmeld" />
                                                    </div>
                                                    
                                                </fieldset>
                                                <script type="text/javascript">
												function checkEmail(email) {
													var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
													if (!filter.test(email)) {
														return false;
													}
													return true;
												}	
												function checkEmailDisable(email) {
													if (!checkEmail(email))  {
														$('#alert').html(' Email er ikke gyldig');
														$('#backoverlay').show();
														$('#show_popup').show();
													} else {
																$.ajax({
																	type: 'POST',
																	url: 'index.php?option=com_jobs&tmpl=3dmaler&view=newsletter&emaildisable='+email,
																	dataType: 'html',		
																	beforeSend: function() {												
																	},
																	complete: function() {
																	},
																	success: function(html) {
																		if(html==0) {
																			$('#tilmeldConfirm h2').html("");	
																			$('#tilmeldConfirm .message').html("Fjern ikke");	
																			$('#newsletteremail').val("");
																			$('#btn_nyh_thank').click();
																			
																		} else {	
																			$('#tilmeldConfirm h2').html("");	
																			$('#tilmeldConfirm .message').html("Din e-mail er blevet fjernet");	
																			$('#newsletteremail').val("");
																			$('#btn_nyh_thank').click();
																		}
																	}
																});
												
													}
												}
												function checkEmailValid(email) {
													if (!checkEmail(email))  {
														$('#alert').html('Email er ikke gyldig');
														$('#backoverlay').show();
														$('#show_popup').show();
													} else {
																$.ajax({
																	type: 'POST',
																	url: 'index.php?option=com_jobs&tmpl=3dmaler&view=newsletter&email='+email,
																	dataType: 'html',		
																	beforeSend: function() {												
																	},
																	complete: function() {
																	},
																	success: function(html) {
																		
																		
																		if(html==0) {
																			
																			$('#tilmeldConfirm h2').html("");	
																			$('#tilmeldConfirm .message').html("Du allerede tilmeldt nyhedsbrevet");	
																			$('#newsletteremail').val("");
																			$('#btn_nyh_thank').click();	
																		} else {
																			
																			
																			$('#tilmeldConfirm h2').html("Tak for tilmeldingen. Du vil fremover modtage vores nyhedsbrev.");	
																			$('#tilmeldConfirm .message').html("Du vil modtage vores seneste nyheder og opdateringer.");	
																			$('#newsletteremail').val("");
																			$('#btn_nyh_thank').click();
																			
																		}
																	}
																});
													}
												}
                                                </script>
                                            </form>
                                        </div>
                                    </div>
                                    <div id="tilmeldConfirm" style="display:none;">
	                                    <div class="content-view">
                                        <h2 class="blue-txt center">Tak for tilmeldingen. Du vil fremover modtage vores nyhedsbrev.</h2>
                                        <p class="message">Du vil modtage vores seneste nyheder og opdateringer.</p>
                                        <a class="button close"  style="cursor:pointer;" onclick="$('#TB_closeWindowButton').click();">Luk</a>
                                        </div>
                                    </div> 
                                </div>
                                
                                <div id="account" class="legend mart27">
                                	<h2 class="title">Din konto</h2>
                                    <div class="inner">
                                    	<p class="user-info">
                                        	<?php 
                                        	 
											  $db =& JFactory::getDBO();
											  $query = "SELECT * FROM #__users WHERE ID= ".$user->id;
											  $db->setQuery( $query );
											  $rowuser = $db->loadObject();		
											  
                                        	  //print_r($user);
                                        	?>
                                        	<?php echo $rowuser->firma_navn;?><br>
                                        	<?php echo $rowuser->adresse;?><br>
                                            Tlf: <?php echo $rowuser->telefone;?><br/>
                                            CVR: <?php echo $rowuser->cvr;?><br/>
                                            <a href="mailto:<?php echo $rowuser->email;?>">
                                            <?php
											$emi = $user->email;
											//echo strlen($emi);
											for($i=0;$i<strlen($emi); $i+=22) { 
												echo substr($emi,$i,22)."<br/>";
											}
											
										   //echo $user->email;
										   ?> 
                                           </a>
                                        </p>
                                        <p>
                                            <span class="points flr"><?php echo $rowuser->amount_money;?></span>
                                            	Pointsaldo:
                                        </p>
                                        <p>
                                        
                                        	<a class="button accoount-edit fll" href="<?php echo JRoute::_("index.php?option=com_jobs&view=myprofile"); ?>">Rediger</a>
                                        	<a class="button buy thickbox flr" href="#TB_inline?height=180&width=360&inlineId=buyPoint">Køb point</a></p>
                                        <div id="buyPoint" style="display:none;">
                                        <div class="content-view">
                                            <?php 
                                              $items = getArticles(38);
                                              echo $items[0]->introtext; 
                                            ?>
                                            <div class="box-btn"><a class="button close" onclick="$('#TB_closeWindowButton').click();" >OK</a></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                
                                <div id="news" class="legend mart27">
                                	<h2 class="title">Nyheder</h2>
                                    <div class="inner">
                                    	    <?php 
                                              $items = getArticles(39);
                                              echo $items[0]->introtext; 
                                            ?>
                                        <a class="more" href="index.php?option=com_content&view=article&id=20">Læs mere...</a> 
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                       
                    </div>
 <div id="hiddenDetailContent" style="display:none;"></div>              
 <div id="hiddenViewContent" style="display:none;"></div>  
 <div id="hiddenViewMyJobStatus" style="display:none;">
    <div class="content-view">
    <h2 class="blue-txt center">Mine opgaver opdateringer !</h2>
    <p class="message"></p>
   
    </div>
</div> 
                                      
  <script type="text/javascript">
  								   function processMyJobStatus(work_id,oldselect,job_id)
								   {
									   sval = $("#works_"+work_id).val();
									   //alert(sval);
									   if(sval==oldselect){
										  $("#hiddenViewMyJobStatus h2").html('Du skal vælge en status, før du kan opdatere. ');	 
										  $("#btnjobstatus").click(); 
										  return;
									   }
									   /*
									   if(sval==45){
										  $("#hiddenViewMyJobStatus h2").html('Kun administator kan lukke opgaven!');	 
										  $("#btnjobstatus").click(); 
										  return;
									   }
									   */
									   
									   $.ajax({
											type: 'POST',
											url: 'index.php?option=com_jobs&tmpl=3dmaler&task=changeJobStatus&work_id='+work_id+'&select_id='+sval,
											dataType: 'html',		
											beforeSend: function() {												
											},
											complete: function() {												
												//$("#btnjobstatus").click();
											},
											success: function(html) {												
												//$("#hiddenViewMyJobStatus").html(html);	
												$("#wok"+work_id+" .task-title").removeClass("green");
												$("#wok"+work_id+" .task-title").removeClass("disabled");
												if(sval==44||sval==45) {
													if(sval==44) {
														$("#wok"+work_id+" .task-title").addClass("green");
													} else {
														$("#wok"+work_id+" .task-title").addClass("disabled");
													}
													
													//$("#wok"+work_id+" .task-title").removeClass("thickbox");
													//$("#wok"+work_id+" .task-title").attr("onclick","");
													//$("#wok"+work_id+" .task-title").attr("onclick","getInfoJob("+job_id+")");
													//$("#wok"+work_id+" .date").attr("style","color:#F00");
													
												} else {
													//$("#wok"+work_id+" .task-title").addClass("thickbox");
													
													//$("#wok"+work_id+" .task-title").attr("onclick","getInfoJob("+job_id+")");
													//$("#wok"+work_id+" .date").attr("style","");
												}
												
												$("#btn_sb_"+work_id).attr("onClick","processMyJobStatus("+work_id+","+sval+","+job_id+");");
												
												$("#hiddenViewMyJobStatus h2").html('Status opdateret.');	 
												$("#btnjobstatus").click();
												
											}
										});
								   }
								   function getInfo(info_id) {
										$.ajax({
											type: 'POST',
											url: 'index.php?option=com_jobs&tmpl=3dmaler&view=jobdetailadd&jid='+info_id,
											dataType: 'html',		
											beforeSend: function() {												
											},
											complete: function() {
												//$("#popup-01").show();
												
											},
											success: function(html) {												
												$("#hiddenDetailContent").html(html);	
												$("#btnpupfr").click();											
											}
										});
									}
                                   
								   function getInfoJob(info_id) {
										$.ajax({
											type: 'POST',
											url: 'index.php?option=com_jobs&tmpl=3dmaler&view=jobdetail&jid='+info_id,
											dataType: 'html',		
											beforeSend: function() {												
											},
											complete: function() {
												//$("#popup-01").show();
												$("#btnmyjobdetail").click();
											},
											success: function(html) {
												
												$("#hiddenViewContent").html(html);
												
											}
										});
									}


	function toggleDiv(otherAddress) {
	   $("#newsletterForm").toggle();
	}

close_popup=function(){		
    		
            $('#backoverlay').hide();
    		$('#show_popup').hide();
    		
      };
</script>
<style>
    img{border: none;}
    .bg_alert{ width:270px; height:115px; background:url("<?php echo $template ?>/img/bg_alert.png") no-repeat top left; margin:0px auto; padding:15px 0px 0px 83px; color:#000;}
    .m35l{ margin-left:35px;}
</style>
<div id="dialog" style="display:none; position: fixed; top: 10%; left: 35%; z-index:10002;"></div>
<div class="bg_alert" id="show_popup" style="display:none; position: fixed; top: 35%; left: 50%; z-index:10003; margin-left:-140px;">
    <span id="f_focus" style="display:none;"></span>
    <div style="margin:0; padding-top:10px; min-height:60px;" id="alert"></div>
    <div style="padding-left: 40px;"><a href="javascript:void(0);" onclick="close_popup();"><img src="<?php echo $template ?>/img/bt_luk.png" alt="" /></a></div>
</div>
<div style="display: none;position: fixed; top: 0;left: 0;width: 100%;height: 100%;background-color: #000000;z-index:10002;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);" id="backoverlay"></div>	